package com.oms.module.merchant.controller;

import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.service.ResponseMessage;

/**
 * @Author zhanghailong QQ38592077
 * @Description TODO
 * @Date 2020/8/14 14:13
 */
@Controller
public class WebsocketController {

    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;

    @MessageMapping("/hello")
    @SendTo("/topic/hello")
//    @CrossOrigin(origins = "http://localhost:8080")
    public String hello(String requestMessage) {
        System.out.println("接收消息：" + requestMessage);
        return "服务端接收到你发的：" + requestMessage;
    }

//    @GetMapping("/sendMsgByUser")
//    public @ResponseBody
//    Object sendMsgByUser(String token, String msg) {
//        simpMessagingTemplate.convertAndSendToUser(token, "/msg", msg);
//        return "success";
//    }
//
//    @GetMapping("/sendMsgByAll")
//    public @ResponseBody
//    Object sendMsgByAll(String msg) {
//        simpMessagingTemplate.convertAndSend("/topic", msg);
//        return "success";
//    }
//
//    @GetMapping("/test")
//    public String test() {
//        return "test-stomp.html";
//    }
}
